import { Component } from '@angular/core';
import {AuthService, LostOrFindService} from "../../services";
import {Occasion} from "../../models/occasion.model";
import {NzNotificationService} from "ng-zorro-antd/notification";

@Component({
  selector: 'app-my-uploads',
  templateUrl: './my-uploads.component.html',
  styleUrl: './my-uploads.component.css'
})
export class MyUploadsComponent {
  occasions: Occasion[] | undefined;
  constructor(
    private notification: NzNotificationService,
    private authService: AuthService,private lostOrFindService: LostOrFindService) {
    this.reload();
  }

  reload() {
    if(this.authService.getIsLoggedIn()){
      this.lostOrFindService.getAllWithLoggedUser(this.authService.user?.id!).subscribe
      ( {
        next: (occasions)=>{
          this.occasions = occasions;
          this.notification.success("加载成功","")
        },
        error: (error) => {
          this.notification.error("加载失败","");
        }
      })
    }
  }

  confirm(occasionId: number){
    this.lostOrFindService.deleteOccasion(occasionId).subscribe({
      next: value => {
        this.notification.success("删除成功","");
        this.reload();
      },
      error: err => {
        this.notification.error("删除失败","")
      }
    });

  }

  cancel() {

  }
}
